{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e5faf80a",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 上周回顾\n",
    "> * 1.list的一般方法/函数的使用及案例，如：\n",
    ">> 1.append()增加，增加list元素到list末尾，常用于新建列表\n",
    ">> 2.pop(index)/remove(values)对比两者优势\n",
    ">> 3.\n",
    "\n",
    "\n",
    "\n",
    "name = \"Yangqian\"\n",
    "name = \"youge\"\n",
    "name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "417d7151",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "i\n",
      "i\n",
      "a\n"
     ]
    }
   ],
   "source": [
    "# 初始字典\n",
    "vowels = ['a','e','i','o','u']\n",
    "word = \"Milliways\"\n",
    "# 检查 word中出现的元音，并打印出来 怎么做？\n",
    "# for letter in word # 第一个元素letter 请不要和已有变量重名\n",
    "                     # 第一个元素一般不定义名字，常用item(元素)来命名\n",
    "                     #                           简写 i 来命名\n",
    "                     # 第二个元素（重要），意味着将遍历的内容\n",
    "                     # 遍历的内容一般是 序列 数据 str list \n",
    "for letter in word:\n",
    "   # print(letter)\n",
    "    if letter in vowels:\n",
    "        print(letter)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "95860f0b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a\n",
      "a\n",
      "e\n",
      "e\n",
      "i\n",
      "i\n",
      "o\n",
      "o\n",
      "u\n",
      "u\n"
     ]
    }
   ],
   "source": [
    "for letter in vowels:\n",
    "    print(letter)\n",
    "    if letter in vowels:\n",
    "        print(letter)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6fff4824",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 使用append()重建列表\n",
    "found = []\n",
    "for letter in word:\n",
    "#     print(letter)\n",
    "   if letter in vowels:\n",
    "        if found not in letter\n",
    "        found.append(letter)\n",
    "found"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "38c05974",
   "metadata": {},
   "outputs": [
    {
     "ename": "IndentationError",
     "evalue": "expected an indented block (<ipython-input-12-ab2f42ba18c5>, line 37)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-12-ab2f42ba18c5>\"\u001b[1;36m, line \u001b[1;32m37\u001b[0m\n\u001b[1;33m    if choice < len(good_list):\u001b[0m\n\u001b[1;37m    ^\u001b[0m\n\u001b[1;31mIndentationError\u001b[0m\u001b[1;31m:\u001b[0m expected an indented block\n"
     ]
    }
   ],
   "source": [
    "# 购物车  \n",
    "# 商品数据信息存放\n",
    "goods_list = [\n",
    "    [\"Python 课本\",60],\n",
    "    [\"华为手机\",8000],\n",
    "    [\"小米手环\",199],\n",
    "    [\"蜜雪冰城\",8]\n",
    "]\n",
    "\n",
    "# 用户购物信息的数据存放\n",
    "user_shopping_list = []   # 增加进来可考虑用append()方法\n",
    "\n",
    "# 用户输入余额信息\n",
    "Alipay = input(\"请输入支付宝的余额：\")\n",
    "# 打印商品信息\n",
    "info = '''------- good list ------\n",
    "商品编号：%s,商品名称：%s,商品价格：%s 元\n",
    "商品编号：%s,商品名称：%s,商品价格：%s 元\n",
    "商品编号：%s,商品名称：%s,商品价格：%s 元\n",
    "商品编号：%s,商品名称：%s,商品价格：%s 元\n",
    "'''%(0,goods_list[0][0],goods_list[0][1],\n",
    "     1,goods_list[0][0],goods_list[0][1],\n",
    "     2,goods_list[0][0],goods_list[0][1],\n",
    "     3,goods_list[0][0],goods_list[0][1],\n",
    ")\n",
    "print(info)\n",
    "# list的长度？ len()\n",
    "print(\"------- good list ------\")\n",
    "for i in range(len(goods_list)):\n",
    "    print(\"商品编号：%s,商品名称：%s,商品价格：%s 元\"%(i,goods_list[i][0],goods_list[i][0]))\n",
    "\n",
    "# 用户输入商品编号，实现商品的查询\n",
    "choice = input(\"请输入商品的编号：\")     # input输入的内容跟默认是字符串str 例如输入2则显示\"2\"\n",
    "if choice.isdigit():\n",
    "\n",
    "# 判断编号是否存在\n",
    "if choice < len(good_list):\n",
    "    # 检查用户余额 > 商品价格\n",
    "    if Alipay > goods_list[choice][1]:\n",
    "        Alipay = Alipay - goods_list[choice][1]# 用户余额发生变化，要扣除\n",
    "        user_shopping_list.append(goods_list[choice])\n",
    "        pass\n",
    "    else:\n",
    "        print(\"您的余额已不足，请更换支付方式，试试花呗？\")\n",
    "else:\n",
    "    print(\"请输入正确的商品编号，您输入的商品不存在\")\n",
    "\n",
    "    \n",
    "# 打印用户余额和用户的商品列表信息\n",
    "print(\"用户余额：%s,购物车：%s\"%(Alipay,user_shopping_list))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "74cb77ce",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
